package com.lanou3g.zjl.chating.home.personal_center;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.chat.EMChatManager;
import com.lanou3g.zjl.chating.R;
import com.lanou3g.zjl.chating.base.BaseFragment;
import com.lanou3g.zjl.chating.home.widget.AddFriendsByQRCode;
import com.lanou3g.zjl.chating.utils.GetUserAvatarHelper;
import com.lanou3g.zjl.chating.volley.VolleySingleton;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by dllo on 15/11/14.
 */
public class PersonalFragment extends BaseFragment {

    private SharedPreferences userAvatar;//存储用户头像地址
    private SharedPreferences.Editor editAvtar;
    private VolleySingleton singleton;
    @Bind(R.id.personalUserHead_Iv)
    CircleImageView personalUserHead_Iv;

    @Bind(R.id.personalUserName_Tv)
    TextView personalUserName_Tv;

    private LocationManager locationManager;
    private String provider;
    private GetUserAvatarHelper helper;

    @Override
    protected View getLayout(LayoutInflater inflater) {
        View v = inflater.inflate(R.layout.fragment_menu_left, null);
        return v;
    }

    @OnClick(R.id.toQR)
    void toQR() {
        Intent intent = new Intent(getActivity(), AddFriendsByQRCode.class);
        startActivity(intent);
    }


    @Override
    protected void initData() {
        // 得到用户名
        String username = EMChatManager.getInstance().getCurrentUser();
        personalUserName_Tv.setText(username);
//        //显示用户头像
//        userAvatar = getActivity().getSharedPreferences("UserAvatar", Context.MODE_PRIVATE);
//        singleton = VolleySingleton.getInstance(getActivity());
//        if(!userAvatar.getString(username, "").equals(""))
//        singleton.getPic(userAvatar.getString(username, ""), personalUserHead_Iv);
        helper = new GetUserAvatarHelper(getActivity(),personalUserHead_Iv,username);
        helper.execute(username);
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }
}
